package com.atguigu.spzx.cloud.order.service.impl;

import com.atguigu.spzx.cloud.order.config.PatternProperties;
import com.atguigu.spzx.cloud.order.config.RestTemplateConfiguration;
import com.atguigu.spzx.cloud.order.entity.Order;
import com.atguigu.spzx.cloud.order.entity.User;
import com.atguigu.spzx.cloud.order.fegin.UserFeignClient;
import com.atguigu.spzx.cloud.order.mapper.OrderMapper;
import com.atguigu.spzx.cloud.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;

// com.atguigu.spzx.cloud.order.service.impl;
@Service
//@RefreshScope
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper ;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private UserFeignClient userFeignClient;
    @Autowired
    private PatternProperties patternProperties;

    @Value("${pattern.dateformat}")
    String dateformat;

    @Override
    public Order findOrderByOrderId(Long orderId) {
        Order order = orderMapper.findOrderByOrderId(orderId);
        Long userId = order.getUserId();
        User user = userFeignClient.findUserByUserId(userId);
//        User user = restTemplate.getForObject("http://spzx-cloud-user/api/user/findUserByUserId/" + userId, User.class);
        order.setUser(user);

        /*System.out.println(dateformat);
        SimpleDateFormat sdf = new SimpleDateFormat(dateformat);
        String format = sdf.format(new Date());
        System.out.println(format);*/

        String pattern = patternProperties.getDateformat();
        System.out.println("pattern = " + pattern);


        return order;
    }

}